<%@ page contentType="application/json;charset=UTF-8" language="java" %><%--
--%><%@ page import="spacecrack.UnitManager" %><%--
--%><%@ page import="spacecrack.UnitManager.Unit" %><%--
--%><%@ page import="spacecrack.UnitManager.Target" %><%--
--%><%@ page import="spacecrack.NameGenerator" %><%--
--%><%-- @ include file="units.json" --%><%--
--%><%

	final UnitManager um = new UnitManager();
	final NameGenerator ng = new NameGenerator();

	final Unit[][] units = new Unit[5][5];

	int id = 0;
	for (int j = 0; j < 5; ++j) {
		for (int i = 0; i < 4; ++i) {
			boolean evenRow = (j%2 == 0);
			if (evenRow && i == 0) continue;

			String uId = "u"+ id++;
			String uName = ng.generateName(id);
			int ux = i*400 - (evenRow ? 200 : 0);
			int uy = j*200;
			int us = (int) (Math.random() * 20);
			final Unit unit = new Unit(uId, uName, ux, uy, us);
			units[i][j] = unit;
			um.addUnit(unit);
		}
	}

	for (int uj = 0; uj < 5; ++uj) {
		for (int ui = 0; ui < 5; ++ui) {
			final Unit u = units[ui][uj];
			if (u == null) continue;

			for (int dj = -1; dj <= 1; ++dj) {
				for (int di = -1; di <= 1; ++di) {
					boolean evenRow = (uj%2 == 0);
					if (!evenRow && dj != 0 && di ==-1) continue;
					if ( evenRow && dj != 0 && di == 1) continue;

					int ti = ui + di;
					int tj = uj + dj;
					if (ti < 0 || ti >= 5) continue;
					if (tj < 0 || tj >= 5) continue;

					final Unit t = units[ti][tj];
					if (t == null) continue;
					if (u == t) continue;

					String tId = t.getId();
					int dx = t.getPosX() - u.getPosX();
					int dy = t.getPosY() - u.getPosY();
					final Target target = new Target(tId, dx/2, dy/2);
					u.addTarget(target);
				}
			}
		}
	}

%><%= um.asJSONValue() %>
